// pages/category/category.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    leftList: [],
    rightList: [],
    currentIndex: 0,
    scrollTop: -1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCategories();
  },
  async getCategories() {
    const { message } = await wx.http({
      url: "/categories",
    });
    this.setData({
      leftList: message,
      rightList: message[0].children,
    });
  },
  //   切换侧边栏
  selectItem(e) {
    const { index } = e.mark;
    const rightList = this.data.leftList[index].children;
    this.setData({
      currentIndex: index,
      rightList,
      scrollTop: 0.01,
    });
  },
  // 给子组件传值
  gotoSearch() {
    wx.navigateTo({
      url:'/pages/search/search'
  })
  },
});
